package com.example.demo.cat;

import lombok.extern.slf4j.Slf4j;
import org.apache.kafka.clients.consumer.ConsumerRecord;
import org.springframework.context.annotation.Scope;
import org.springframework.kafka.listener.AcknowledgingMessageListener;
import org.springframework.kafka.listener.MessageListener;
import org.springframework.kafka.support.Acknowledgment;
import org.springframework.stereotype.Service;

import java.io.IOException;


@Slf4j
public class SingleAckMessageListener implements AcknowledgingMessageListener<String, String> {


    @Override
    public void onMessage(ConsumerRecord<String, String> data) {
        AcknowledgingMessageListener.super.onMessage(data);
    }


    @Override
    public void onMessage(ConsumerRecord<String, String> record, Acknowledgment acknowledgment) {

        log.info("Before receiving:" + record.toString());
        String value = record.value();
        log.info("===========开始提交offset=============");
        acknowledgment.acknowledge();//提交offset
        log.info("===========已经提交offset=============");
    }
}
